import { HaConfigOption } from '.';
import { DeviceClass, monetaryList } from './common';

const sensorDeviceClasses = [
    DeviceClass.ApparentPower,
    DeviceClass.Aqi,
    DeviceClass.Area,
    DeviceClass.AtmosphericPressure,
    DeviceClass.Battery,
    DeviceClass.BloodGlucoseConcentration,
    DeviceClass.CarbonDioxide,
    DeviceClass.CarbonMonoxide,
    DeviceClass.Conductivity,
    DeviceClass.Current,
    DeviceClass.DataRate,
    DeviceClass.DataSize,
    DeviceClass.Date,
    DeviceClass.Distance,
    DeviceClass.Duration,
    DeviceClass.Energy,
    DeviceClass.EnergyStorage,
    DeviceClass.Enum,
    DeviceClass.Frequency,
    DeviceClass.Gas,
    DeviceClass.Humidity,
    DeviceClass.Illuminance,
    DeviceClass.Irradiance,
    DeviceClass.Moisture,
    DeviceClass.Monetary,
    DeviceClass.NitrogenDioxide,
    DeviceClass.NitrogenMonoxide,
    DeviceClass.NitrousOxide,
    DeviceClass.Ozone,
    DeviceClass.Pm1,
    DeviceClass.Pm10,
    DeviceClass.Pm25,
    DeviceClass.PotentialHydrogen,
    DeviceClass.Power,
    DeviceClass.PowerFactor,
    DeviceClass.Precipitation,
    DeviceClass.PrecipitationIntensity,
    DeviceClass.Pressure,
    DeviceClass.ReactivePower,
    DeviceClass.SignalStrength,
    DeviceClass.SoundPressure,
    DeviceClass.Speed,
    DeviceClass.SulphurDioxide,
    DeviceClass.Temperature,
    DeviceClass.Timestamp,
    DeviceClass.VolatileOrganicCompounds,
    DeviceClass.VolatileOrganicCompoundsParts,
    DeviceClass.Voltage,
    DeviceClass.Volume,
    DeviceClass.VolumeFlowRate,
    DeviceClass.VolumeStorage,
    DeviceClass.Water,
    DeviceClass.Weight,
    DeviceClass.WindSpeed,
] as const;

export const sensorUnitOfMeasurement: Record<
    (typeof sensorDeviceClasses)[number],
    null | string[]
> = {
    apparent_power: ['VA'],
    aqi: null,
    area: ['m²', 'cm²', 'km²', 'mm²', 'in²', 'ft²', 'yd²', 'mi²', 'ac', 'ha'],
    atmospheric_pressure: [
        'cbar',
        'bar',
        'hPa',
        'inHg',
        'kPa',
        'mbar',
        'Pa',
        'psi',
    ],
    battery: ['%'],
    blood_glucose_concentration: ['mg/dL', 'mmol/L'],
    carbon_dioxide: ['ppm'],
    carbon_monoxide: ['ppm'],
    conductivity: ['S/cm', 'mS/cm', 'µS/cm'],
    current: ['A'],
    data_rate: [
        'bit/s',
        'kbit/s',
        'Mbit/s',
        'Gbit/s',
        'B/s',
        'kB/s',
        'MB/s',
        'GB/s',
        'KiB/s',
        'MiB/s',
        'GiB/s',
    ],
    data_size: [
        'bit',
        'kbit',
        'Mbit',
        'Gbit',
        'B',
        'kB',
        'MB',
        'GB',
        'TB',
        'PB',
        'EB',
        'ZB',
        'YB',
        'KiB',
        'MiB',
        'GiB',
        'TiB',
        'PiB',
        'EiB',
        'ZiB',
        'YiB',
    ],
    date: null,
    distance: ['km', 'm', 'cm', 'mm', 'mi', 'yd', 'in'],
    duration: ['d', 'h', 'min', 's', 'ms', 'µs'],
    energy: ['Wh', 'kWh', 'MWh', 'GJ'],
    energy_storage: ['Wh', 'kWh', 'MWh', 'MJ', 'GJ'],
    enum: null,
    frequency: ['Hz', 'kHz', 'MHz', 'GHz'],
    gas: ['m³', 'ft³'],
    humidity: ['%'],
    illuminance: ['lx', 'lm'],
    irradiance: ['W/m²', 'BTU/(h*ft²)'],
    moisture: ['%'],
    monetary: monetaryList,
    nitrogen_dioxide: ['µg/m³'],
    nitrogen_monoxide: ['µg/m³'],
    nitrous_oxide: ['µg/m³'],
    ozone: ['µg/m³'],
    pm1: ['µg/m³'],
    pm25: ['µg/m³'],
    pm10: ['µg/m³'],
    potential_hydrogen: null,
    power: ['W', 'kW'],
    power_factor: ['%'],
    precipitation: ['mm', 'in', 'cm'],
    precipitation_intensity: ['mm/h', 'mm/d', 'in/h', 'in/d'],
    pressure: ['cbar', 'bar', 'hPa', 'inHg', 'kPa', 'mbar', 'Pa', 'psi'],
    reactive_power: ['var'],
    signal_strength: ['dB', 'dBm'],
    sound_pressure: ['dB', 'dBA'],
    speed: [
        'ft/s',
        'in/s',
        'in/d',
        'in/h',
        'km/h',
        'kn',
        'm/min',
        'm/s',
        'mm/s',
        'mm/h',
        'mm/d',
        'mph',
    ],
    sulphur_dioxide: ['µg/m³'],
    temperature: ['°C', '°F'],
    timestamp: null,
    volatile_organic_compounds: ['µg/m³'],
    volatile_organic_compounds_parts: ['ppm', 'ppb'],
    voltage: ['V'],
    volume: ['fl. oz.', 'ft³', 'gal', 'L', 'mL', 'm³'],
    volume_flow_rate: ['m³/h', 'ft³/min', 'L/min', 'gal/min', 'mL/s'],
    volume_storage: ['L', 'mL', 'gal', 'fl. oz.', 'm³', 'ft³', 'CCF'],
    water: ['L', 'gal', 'm³', 'ft³'],
    weight: ['g', 'kg', 'lb', 'mg', 'oz', 'µg'],
    wind_speed: ['ft/s', 'km/h', 'kn', 'm/s', 'mph'],
};

export default [
    {
        id: 'entity_category',
        type: 'select',
        values: ['', 'diagnostic'],
    },
    {
        id: 'device_class',
        type: 'select',
        values: ['', ...sensorDeviceClasses],
    },
    {
        id: 'unit_of_measurement',
        type: 'unit_of_measurement',
        values: sensorUnitOfMeasurement,
    },
    {
        id: 'state_class',
        type: 'select',
        values: ['', 'measurement', 'total', 'total_increasing'],
    },
    { id: 'last_reset', type: 'datetime' },
] as HaConfigOption[];
